package com.vancouver.knows.ui.fragment.citynews;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import com.pangu.task.mark.ATaskMark;
import com.pangu.ui.refresh.ARefreshViewController;
import com.pangu.ui.refresh.RefreshControllerView;
import com.vancouver.knows.MainApplication;
import com.vancouver.knows.business.BusinessModule;

/**
 * 城事下拉界面
 * 
 * @author chenxunlin01
 * 
 */
public class CityNewsPullControllerView extends RefreshControllerView {

	public CityNewsPullControllerView(Context context) {
		super(context);
	}

	public CityNewsPullControllerView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public void onRefresh(ARefreshViewController controller) {
		((CityNewsListView) content).handleRefreshLoadItem();
	}

//	public void loadData(ATaskMark aTaskMark) {
//		((CityNewsListView) content).initLoadableView(aTaskMark);
//	}

	/**
	 * 热门， 最新， 资讯， 灌水，求助，二手
	 * 推荐/大温/加国/专题/快闻/轻话题
	 * @param type
     */
	public void loadData(int type, String titles[]) {
		BusinessModule module = ((MainApplication) imContext).getBusinessModule();
		ATaskMark aTaskMark = null;
		switch (type) {
		case CityNewsChildrenFragment.CITYNEWS_TYPE_HOT:
			aTaskMark = module.getTaskMarkPool().getFetchCityNewsTaskMarkList("", titles[0]);
			break;
		case CityNewsChildrenFragment.CITYNEWS_TYPE_MUSIC_MATCH:
			aTaskMark = module.getTaskMarkPool().getFetchCityNewsTaskMarkList("", titles[1]);
			break;
		case CityNewsChildrenFragment.CITYNEWS_TYPE_NEWEST:
			aTaskMark = module.getTaskMarkPool().getFetchCityNewsTaskMarkList("", titles[2]);
			break;
		case CityNewsChildrenFragment.CITYNEWS_TYPE_INFORMATION:
			aTaskMark = module.getTaskMarkPool().getFetchCityNewsTaskMarkList("", titles[3]);
			break;
		case CityNewsChildrenFragment.CITYNEWS_TYPE_IRRIGATION:
			aTaskMark = module.getTaskMarkPool().getFetchCityNewsTaskMarkList("", titles[4]);
			break;
		case CityNewsChildrenFragment.CITYNEWS_TYPE_SECONDHAND:
			aTaskMark = module.getTaskMarkPool().getFetchCityNewsTaskMarkList("", titles[5]);
			break;
		case CityNewsChildrenFragment.CITYNEWS_TYPE_SHIPING:
			aTaskMark = module.getTaskMarkPool().getFetchCityNewsTaskMarkList("", titles[6]);
			break;
		}
		((CityNewsListView) content).initLoadableView(aTaskMark);
	}

	public void flush() {
		((CityNewsListView) content).notifyDataSetChanged();
	}

	@Override
	protected View createContentView() {
		return new CityNewsListView(getContext(), this);
	}

}
